package com.movieproject.dataobjects;


import java.util.Set;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.OneToMany;
import javax.persistence.Table;

import org.apache.lucene.document.Field.Index;
import org.apache.solr.analysis.StandardTokenizerFactory;
import org.apache.solr.analysis.LowerCaseFilterFactory;
import org.apache.solr.analysis.NGramFilterFactory;
import org.hibernate.search.annotations.Analyzer;
import org.hibernate.search.annotations.AnalyzerDefs;
import org.hibernate.search.annotations.AnalyzerDef;
import org.hibernate.search.annotations.Field;
import org.hibernate.search.annotations.Store;
import org.hibernate.search.annotations.TokenizerDef;
import org.hibernate.search.annotations.TokenFilterDef;
import org.hibernate.search.annotations.Parameter;
import org.hibernate.search.annotations.Indexed;

@Entity
@Indexed
@AnalyzerDefs({
	@AnalyzerDef(name = "ngram",
		tokenizer = @TokenizerDef(factory = StandardTokenizerFactory.class),
		filters = {
		@TokenFilterDef(factory = LowerCaseFilterFactory.class),
	    @TokenFilterDef(factory = NGramFilterFactory.class, 
	    params = {
	    		@Parameter(name = "minGramSize",value = "3"),
	    		@Parameter(name = "maxGramSize",value = "1024") 
	    })
	})
})
@Table(name="movies")
public class Movie {
    	@Id @GeneratedValue
    	@Column(name = "MovieID")
    	private int movieID;
    	
    	@Column(name = "Actors")
    	@Field(store = Store.YES, analyzer = @Analyzer(definition = "ngram"))
	private String actors;
    	
    	@Column(name = "Description")
    	@Field
	private String description;
    	
    	@Column(name = "Genre")
    	@Field
	private String genre;
    	
    	@Column(name = "ImageURL")
	private String imageURL;
    	
    	@Column(name = "Rating")
	private String rating;
    	
    	@Column(name = "Title")
    	@Field(store = Store.YES, analyzer = @Analyzer(definition = "ngram"))
	private String title;
    	
    	@Column(name = "Year")
    	@Field
	private String year;
    	
    	@OneToMany(mappedBy = "movie")
    	private Set<InventoryItem> inventoryItems;;
    	
    	@OneToMany(mappedBy = "movie")
    	private Set<QueueRecord> queueRecords;
    	
    	@OneToMany(mappedBy = "review")
    	private Set<Review> reviews;
	
	public Movie(String title, String actors, String description, String genre,
		String imageURL, String rating, String year) {
	    super();
	    this.actors = actors;
	    this.description = description;
	    this.genre = genre;
	    this.imageURL = imageURL;
	    this.rating = rating;
	    this.title = title;
	    this.year = year;
	}
	public Movie(){}
	public int getMovieID() {
	    return movieID;
	}
	public void setMovieID(int movieID) {
	    this.movieID = movieID;
	}
	public String getActors() {
	    return actors;
	}
	public void setActors(String actors) {
	    this.actors = actors;
	}
	public String getDescription() {
	    return description;
	}
	public void setDescription(String description) {
	    this.description = description;
	}
	public String getGenre() {
	    return genre;
	}
	public void setGenre(String genre) {
	    this.genre = genre;
	}
	public String getImageURL() {
	    return imageURL;
	}
	public void setImageURL(String imageURL) {
	    this.imageURL = imageURL;
	}
	public String getRating() {
	    return rating;
	}
	public void setRating(String rating) {
	    this.rating = rating;
	}
	public String getTitle() {
	    return title;
	}
	public void setTitle(String title) {
	    this.title = title;
	}
	public String getYear() {
	    return year;
	}
	public void setYear(String year) {
	    this.year = year;
	}
}
